package Page.AchievementPage;

import Dao.AchievementDao;
import DataClass.Achievement;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

import java.net.URL;
import java.sql.SQLException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

public class AchievementController implements Initializable{
    @FXML
    private TableView<Achievement> AchievementTable;

    @FXML
    private TableColumn aNo;
    @FXML
    private TableColumn aTime;
    @FXML
    private TableColumn aId;
    @FXML
    private TableColumn aName;
    @FXML
    private TableColumn aProposer;
    @FXML
    private TableColumn aInventor;
    @FXML
    private TableColumn aState;


    private AchievementModel viewModel;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        viewModel = new AchievementModel();

        aNo.setCellValueFactory(new PropertyValueFactory<Achievement,Integer>("aNo"));
        aTime.setCellValueFactory(new PropertyValueFactory<Achievement,String>("aTime"));
        aId.setCellValueFactory(new PropertyValueFactory<Achievement,String>("aId"));
        aName.setCellValueFactory(new PropertyValueFactory<Achievement,String>("aName"));
        aProposer.setCellValueFactory(new PropertyValueFactory<Achievement,String>("aProposer"));
        aInventor.setCellValueFactory(new PropertyValueFactory<Achievement,String>("aInventor"));
        aState.setCellValueFactory(new PropertyValueFactory<Achievement,String>("aState"));


        AchievementTable.setItems(viewModel.dataListProperty());

        try {
            // 从数据库或其他来源获取数据
            viewModel.setDataList(AchievementDao.getAchievement());
        } catch (SQLException e) {
            viewModel.setDataList(new ArrayList<>());
            System.err.println("Achievement 数据获取失败" + e.getMessage());
        }
    }

    public void backButtonClicked(javafx.event.ActionEvent actionEvent) {
        viewModel.backButtonClicked();
    }
}
